<?php
class ClsBReport extends ClsNaanalBusiness
{
    private $objPDO=null;
    /**
     * from date as integer
     * @var type 
     */
    private $from=0;
    /**
     * to date as integer
     * @var type 
     */
    private $to=0;
    public function __construct()
    { 
        
    }
    public function init()
    {
        
    }
    public function setRange($from,$to)
    {
        $this->from=$from;
        $this->to=$to;
    }
    public function getSQL($isAlumini=false)
    {
        $sql="select * from vtiger_invoice inner join vtiger_crmentity on vtiger_invoice.invoiceid=vtiger_crmentity.crmid inner join vtiger_invoicecf on vtiger_invoice.invoiceid=vtiger_invoicecf.invoiceid";
        $sql=$sql." where";
        $sql=$sql." vtiger_crmentity.deleted=0";
        $from=date("Y-m-d H:i:s",$this->from);
        $to=date("Y-m-d H:i:s",$this->to);
        $sql=$sql." and vtiger_crmentity.createdtime between '{$from}' and '{$to}'";
        return $sql;
    }
    public function getEnquiryReport()
    {
        $objPDO=ClsNaanalPDO::getInstance();
        $sql=$this->getSQL();
        $objPDO->setQuery($sql);

        $myPDO=ClsLPDO::getNamedInstance();
        $obj=new ClsNaanalRecords($sql,$myPDO);
        
        $recordCount=$obj->getRecordCount();
        $columnCount=$obj->getColumnCount();

        $arrData=array();
        $objPHPExcel=ClsNaanalLibrary::getInstance("phpexcel");
        for($j=0;$j<$columnCount;$j++)
        {
            $head=$obj->getHead($j);
            $objPHPExcel->addData($j,0,$j,0,$head);
        }
        for($i=2;$i<=($recordCount+1);$i++)
        {
            for($j=0;$j<$columnCount;$j++)
            {
                $data=$obj->getData($i-2, $j);
                $objPHPExcel->addData($j,$i,$j,$i,$data);
            }
        }
        $objPHPExcel->render();
        $objPHPExcel->save(NAANAL_APP_PATH."report.xls");
        ClsNaanalDownload::getInstance()->download(NAANAL_APP_PATH."report.xls");
        
        return($arrCellInfo);
    }
    public function render()
    {
        
    }
}
?>